<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!-- 主体内容 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header" style="color:#d02e25;font-family: '楷体'; ">
            添加文章
        </div>

        <form class="layui-form" id="form1">
            <div class="layui-card-body">

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">文章类别</label>
                    <div class="layui-input-inline">
                        <input type="text" name="typeName"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>

                    <label class="layui-form-label">文章来源</label>
                    <div class="layui-input-inline">
                        <input type="text" name="theSource"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>


                    <label class="layui-form-label">录入者</label>
                    <div class="layui-input-inline">
                        <input type="text" name="inputer"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">文章状态</label>
                    <div class="layui-input-inline">
                        <input type="text" name="status"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>

                    <label class="layui-form-label">关键字</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keyword"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>


                    <label class="layui-form-label">简介</label>
                    <div class="layui-input-inline">
                        <input type="text" name="introduce"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <%--<label class="layui-form-label">阅读量</label>--%>
                    <%--<div class="layui-input-inline">--%>
                        <%--<input type="text" name="hits"--%>
                               <%--autocomplete="off" class="layui-input">--%>

                    <%--</div>--%>

                    <%--<label class="layui-form-label">评论数</label>--%>
                    <%--<div class="layui-input-inline">--%>
                        <%--<input type="text" name="postNum"--%>
                               <%--autocomplete="off" class="layui-input">--%>
                    <%--</div>--%>


                    <label class="layui-form-label">&nbsp;</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="ontop" id="ontop" title="是否置顶">
                        <input type="checkbox" name="isslite" id="isslite" title="是否推荐">
                    </div>
                </div>



                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">文章标题</label>
                    <div class="layui-input-inline" style="width: 44.5%;">
                        <input type="text" name="title"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>

                    <label class="layui-form-label">副标题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="subTitle"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <textarea id="content" name="content"></textarea>
                </div>


                <div class="layui-form-item">
                    <div class="layui-input-block" style="text-align: center;">
                        <button class="layui-btn" lay-submit lay-filter="ok">提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary" id="reset">重置</button>
                    </div>
                </div>



            </div>
        </form>





    </div>
</div>
</div>

<script type="application/javascript">


    var layedit;
    var editDoctorMsg;
    var form = layui.form;
    form.render();
    layui.use('layedit', function(){
        layedit = layui.layedit;
        //上传图片,必须放在 创建一个编辑器前面
        layedit.set({
            uploadImage: {
                url: '/api/spfile/upload' //接口url
                ,type: 'post' //默认post
            }
        });
        editDoctorMsg = layedit.build('content', {
            height: '60%' //设置编辑器高度
        });
    });

    var editIndex = layedit.build('content',{
        // height: 200,
        tool: [
            'strong' //加粗
            ,'italic' //斜体
            ,'underline' //下划线
            ,'del' //删除线
            ,'|' //分割线
            ,'left' //左对齐
            ,'center' //居中对齐
            ,'right' //右对齐
            ,'link' //超链接
            ,'unlink' //清除链接
            ,'face' //表情
            ,'image'//插入图片
        ]
    });

</script>

<script type="application/javascript">
    //保存信息
    form.on('submit(ok)',function (data) {
        data.field.createTime = new Date().getTime();
        data.field.addTime = new Date().getTime();
        data.field.content = layedit.getContent(editIndex);  //将富文本框中的内容取出来放到对象的属性中
        if(data.field.ontop=="on"){
            data.field.ontop=1;
        }else {
            data.field.ontop=0;
        }
        if(data.field.isslite=="on"){
            data.field.isslite=1;
        }else {
            data.field.isslite=0;
        }


        $.ajax({
            type:"post",
            url:"/ajax/party/admin/addArticle",
            contentType : 'application/json;charset=utf-8',
            //设置请求头信息
            dataType:"json",
            data:JSON.stringify(data.field),
            success:function (res) {
                if(res.code==0){
                    layer.alert("保存成功");
                    reset();
                }
            }
        })
        console.log(data.field);
        return false;
    })

    function reset() {
        $("#reset").click();
    }


</script>